<template>
  <el-dialog :title="dialog.title" :visible.sync="dialog.show" width="600px" custom-class="mydialog" append-to-body @close="handleClose">
    <div class="dialog-content">
      <el-form ref="form1" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="品类名称：" >
          <el-input v-model="form.categoryName" maxlength="50" />
        </el-form-item>
      </el-form>
      <div class="text-center mt-30">
        <el-button class="greenbt" type="primary" @click="submitBut()">保存</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { post } from '@/api/utils'
export default{
  props: {
    modalStaticData: {
      type: Object,
      default: () => {}
    },
    // 父组件调用时传进来的参数
    modalData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      dialog: {
        title: '', show: true
      },
      form: {
        code: '', categoryId: '', categoryName: ''
      },
      rules: {},
      options: []

    }
  },
  mounted() {
    if (this.modalData.type === 'edict') {
      this.form.categoryId = this.modalData.sku.categoryId
      this.form.categoryName = this.modalData.sku.categoryName
    } else {
      this.form.categoryId = ''
      this.form.categoryName = ''
    }
  },
  methods: {
    handleClose() {
      this.$emit('close')
    },
    // 保存
    submitBut() {
      if (this.form.categoryName === null || this.form.categoryName === '') {
        this.$message({ message: '品类名称不能为空！' })
        return
      }

      var data = { 'categoryId': this.form.categoryId, 'categoryName': this.form.categoryName }
      post('/wxh-cloud-rest/rest/', '/pas/sku/wxhCategory', data)
        .then(response => {
          if (response.data.status === 'success') {
            this.$message({
              message: response.data.messge
            })
            this.handleClose()
          } else {
            this.options = []
          }
        }).finally(() => {
          this.modalStaticData.closeChildAndRefresh()
        })
    }

  }
}
</script>

